package com.smbms.service.impl;

import com.smbms.mapper.UserMapper;
import com.smbms.pojo.User;
import com.smbms.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

//删除
    public boolean del(Long id) throws Exception {
        if(userMapper.del(id)>0){
            return true;
        }
        return false;
    }
//登录
    public User login(User user) throws SQLException {
        return userMapper.findByIdCodeAndPwd(user);
    }
//查所有
    public List<User> showAllList() throws Exception {


        return userMapper.findAll();
    }


//    增加方法
    public boolean addUser(User user) throws Exception {
        if(userMapper.insert(user)>0){
            return true;
        }
        return false;

    }
//修改
    public boolean updateUser(User user) throws Exception {
        if(userMapper.updateById(user)>0){
            return true;
        }else {
            return false;
        }

    }
//根据id显示个人用户信息
    public User showUserById(long id) throws Exception {
        return userMapper.findUserById(id);
    }



}
